/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package collision;

    
/**
 *
 * @author Marina
 */
public class Table {
    private int[][] matriz;
    private int YBEGIN = 285;
    private int XBEGIN = 145;
    private int YEND = 455;
    private int XEND = 580;
    private int NUMCOL = 11;
    private int NUMROW = 6;
    private int XTAM = 40;
    private int YTAM = 30;

    public int getNUMROW() {
        return NUMROW;
    }

    public void setNUMROW(int NUMROW) {
        this.NUMROW = NUMROW;
    }

    public int getXBEGIN() {
        return XBEGIN;
    }

    public void setXBEGIN(int XBEGIN) {
        this.XBEGIN = XBEGIN;
    }

    public int getXEND() {
        return XEND;
    }

    public void setXEND(int XEND) {
        this.XEND = XEND;
    }

    public int getXTAM() {
        return XTAM;
    }

    public void setXTAM(int XTAM) {
        this.XTAM = XTAM;
    }

    public int getYBEGIN() {
        return YBEGIN;
    }

    public void setYBEGIN(int YBEGIN) {
        this.YBEGIN = YBEGIN;
    }

    public int getYEND() {
        return YEND;
    }

    public void setYEND(int YEND) {
        this.YEND = YEND;
    }

    public int getYTAM() {
        return YTAM;
    }

    public void setYTAM(int YTAM) {
        this.YTAM = YTAM;
    }
    

    public Table() {
        matriz = new int[NUMROW][NUMCOL];
    }
    
    public int findRow(int y){
        
        if(y < YBEGIN || y > YEND )
            return -1;

        y = y - YBEGIN;
        
        for( int i = 0; i < NUMROW; i++){
            if(y < (i*YTAM)) return -1;
            if(y > (i*YTAM) && y < (i*YTAM)+20) return i;
        }
        
        return -1;       
    }
    
    public int findCol(int x){
        if( x < XBEGIN || x > XEND )
            return -1;
        
        x = x - XBEGIN;
        
        for(int i = 0; i < NUMCOL; i++){
            if(x < (i*XTAM)) return -1;
            if(x > (i*XTAM) && x < (i*XTAM)+ 35) return i;
        }
        return -1;
    }
    
    public int insertY(int y){
        
        int row = findRow(y);
        
        if(row == -1)
            return -1;
        else return( YBEGIN + row * YTAM);
    }
    
    public int insertX(int x){
        
        int col = findCol(x);
        
        if(col == -1)
            return -1;
        else return( XBEGIN + col * XTAM + 35/2);
    }
    
    public boolean isVisible(int x, int y){
        
        int posx = insertX(x);
        int posy = insertY(y);
        
        if(posx == -1 || posy == -1)
            return false;
        else return true;
    }

    public boolean isFree(int y, int x)
    {
        int row = findRow(y);
        int col = findCol(x);
        
        if( col == -1 || row == -1)
            return false;
        
        if(matriz[row][col] == 1)
            return false;
        else return true;
    }
    
    
}
